<?php $this->headLink()->prependStylesheet(Ac_Util::getImageBaseUrl('/css/custom_ad_detail.v-'.AC_VERSION.'.css'))?>
<?php $this->headLink()->appendStylesheet(Ac_Util::getImageBaseUrl('/css/custom_acc.v-'.AC_VERSION.'.css'))?>
<?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/tipsy/jquery.tipsy.v-'.AC_VERSION.'.js')) ?>
<?php $this->headLink()->appendStylesheet(Ac_Util::getImageBaseUrl('/css/tipsy/tipsy.v-'.AC_VERSION.'.css')) ?>
<?php $this->JQuery()->javascriptCaptureStart()?>
var uploader;

$j('#tips').tipsy({html: true, fallback: "<p style='text-align:left'><?php echo $this->t('Personalize your account by adding your photo')?></p>" });
$j('#tips').tipsy({html: true, fallback: "<p style='text-align:left'><?php echo $this->t('Personalize your account by adding your photo')?></p>" });

$j(document).ready(function() {
	
    $j('a.change').each(function() {
        $j(this).click(function() {
            var div = $j(this).attr('rel');
            if (div == 'profile_photo') {
                $j('#change_photo').toggle();
                $j('#hide_photo').toggle();
            }
            if (div == 'profile_name') {
                $j('#change_name').toggle();
                $j('#hide_name').toggle();
            }
            if (div == 'profile_phone') {
                $j('#change_phone').toggle();
                $j('#hide_phone').toggle();
            }
            $j('#'+div).toggle(200, function() {
                if (div == 'profile_photo') {
                    
                }
            });
            $j('#'+div).parent().find('.info').toggle();
            return false;
        });
    });
});

$j(function() {

	uploader = new plupload.Uploader({
		runtimes : 'html5,flash,html4',
		browse_button : 'pickfiles',
		container : 'container_uploader',
		max_file_size : '10mb',
		url : '/default/upload/company-pic',
		flash_swf_url : '/plupload/js/plupload.flash.swf',
		silverlight_xap_url : '/plupload/js/plupload.silverlight.xap',
		filters : [
			{title : "Image files", extensions : "jpeg,jpg,gif,png"},
			{title : "Zip files", extensions : "zip"}
		],
		resize : {width : 320, height : 240, quality : 90}
	});

	uploader.bind('Error', function(up, err) {
		$j('#filelist').append("<div>Error: " + err.code +
			", Message: " + err.message +
			(err.file ? ", File: " + err.file.name : "") +
			"</div>"
		);

		up.refresh(); // Reposition Flash/Silverlight
	});

	uploader.bind('FileUploaded', function(up, file, res) {
        var response = $j.parseJSON(res.response);
		$j('#' + file.id + " b").html("100%");
        //var img = $j('img').attr("src",response.url).html();
        $j('#profile_pic_cnt').empty();
        $j(document.createElement("img"))
            .attr({ src: response.url, rel:response.ori, id:'profile_pic_to_be'})
            .appendTo($j('#profile_pic_cnt'))

        $j.ajax({
            type: 'POST',
            url: '<?php echo $this->geturl('confirm-profile-pic', 'user')?>',
            data: {url:response.ori, 'type':'company'},
            success:function () {
                $j('#holder_pic').attr('src',response.url);
            }
        });
	});

	// Client side form validation
	$j('#form_uploader').submit(function(e) {
		var uploader = $j('#uploader').pluploadQueue();

		// Validate number of uploaded files
		if (uploader.total.uploaded == 0) {
			// Files in queue upload them first
			if (uploader.files.length > 0) {
				// When all files are uploaded submit form
				uploader.bind('UploadProgress', function() {
					if (uploader.total.uploaded == uploader.files.length)
						$j('form').submit();
				});

				uploader.start();
			} else
				alert('You must at least upload one file.');

			e.preventDefault();
		}
	});


    $j('#main_form').submit(function(e) {
        var str_length = $j('#username').attr('value').length;
        if ( ($j('#username').attr('value') != '') &&
             (
                (str_length <= 30) &&
                (str_length >= 4)
             )
           )
        {
            $j.post(
                '<?php echo $this->geturl('account-holder-name','user')?>',
                $j('#main_form').serialize(),
                function (data) {
                    if (data != 'nok') {
                        if ($j('#profile_username').attr('value') != '')  { $j('#un_error').hide(); }
                        $j('#update_message').show().delay(3000).fadeOut();
                    }
                    else {
                        if ($j('#username').attr('value') != '') {
                            $j('#un_error1').show();
                        }                        
                    }
                }
            );            
        }
        else {
            if ($j('#username').attr('value') == '')  {
                $j('#un_error').show();
            }
            else {
                if ((str_length >= 30) || (str_length <= 4)) {
                    $j('#un_error2').show();
                }
                else {
                    $j('#un_error2').hide();
                }
                $j('#un_error').hide();
            }            
        }
        /*return false;
   	});    
   	
   	$j('#main_form').submit(function(e) {*/
        if (($j('#phone').attr('value').match(/^\d+$/) != null)  ||
            ($j('#phone').attr('value') != ''))
        { 
            $j.post(
                '<?php echo $this->geturl('account-holder-phone','user')?>',
                $j('#main_form').serialize(),
                function (data) {
                    $j('#update_message').show().delay(3000).fadeOut();
                }
            );
            if ($j('#phone').attr('value') != '') { $j('#ph_error1').hide(); }
            if ($j('#phone').attr('value').match(/^\d+$/) != null) { $j('#ph_error2').hide(); }
        }
        else {  
            if ($j('#phone').attr('value') != '') {
                if ($j('#phone').attr('value').match(/^\d+$/) == null) {
                    $j('#ph_error2').show(); }
                else {
                    $j('#ph_error2').hide(); }
            } else{
				$j('#ph_error1').show();
			}           
        }
        
        if ($j('#agent_num').attr('value') != '' || $j('#contat_msn').attr('value') != '' || $j('#contat_tel').attr('value') != '' || $j('#contat_name').attr('value') != '' || $j('#services').attr('value') != '')
        { 
            $j.post(
                '<?php echo $this->geturl('account-holder-contact-tel','user')?>',
                $j('#main_form').serialize(),
                function (data) {
                    $j('#update_message').show().delay(3000).fadeOut();
                }
            );
        }
        
        /*if ($j('#services').attr('value') != '')
        { 
            $j.post(
                '<?php echo $this->geturl('account-holder-services','user')?>',
                $j('#main_form').serialize(),
                function (data) {
                    $j('#se_success').show().delay(5000).fadeOut();
                }
            );
        }
        
        if ($j('#contact_name').attr('value') != '')
        { 
            $j.post(
                '<?php echo $this->geturl('account-holder-contact-name','user')?>',
                $j('#main_form').serialize(),
                function (data) {
                    $j('#cn_success').show().delay(5000).fadeOut();
                }
            );
        }
        
        if ($j('#contact_tel').attr('value') != '')
        { 
            $j.post(
                '<?php echo $this->geturl('account-holder-contact-tel','user')?>',
                $j('#main_form').serialize(),
                function (data) {
                    $j('#ct_success').show().delay(5000).fadeOut();
                }
            );
        }
        
        if ($j('#contat_msn').attr('value') != '')
        { 
            $j.post(
                '<?php echo $this->geturl('account-holder-contact-msn','user')?>',
                $j('#main_form').serialize(),
                function (data) {
                    $j('#cm_success').show().delay(5000).fadeOut();
                }
            );
        }*/
        
        return false;
    });    
    
    setTimeout(function() {
        uploader.init();
        uploader.bind('FilesAdded', function(up, files) {
            uploader.start();
        });
    });
});
<?php $this->JQuery()->javascriptCaptureEnd()?>
<?php $this->JQuery()->addJavascriptFile('http://bp.yahooapis.com/2.4.21/browserplus-min.js')?>

    <?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/plupload/plupload.v-'.AC_VERSION.'.js'))?>
    <?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/plupload/plupload.html5.v-'.AC_VERSION.'.js'))?>
    <?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/plupload/plupload.html4.v-'.AC_VERSION.'.js'))?>

    <?php $this->JQuery()->addJavascriptFile(Ac_Util::getImageBaseUrl('/js/plupload/jquery.plupload.queue.min.v-'.AC_VERSION.'.js'))?>
<?php if (IS_LIVE):?>
    <?php $this->headLink()->appendStylesheet(Ac_Util::getImageBaseUrl('/css/plupload/plupload.queue.v-'.AC_VERSION.'.css'))?>
<?php endif;?>
<?php $this->jQuery()->uiEnable()?>
<?php $this->headStyle()->captureStart()?>
.toggle  {float:none;clear:both;}
<?php $this->headStyle()->captureEnd()?>
<?php $this->placeholder('container-class')->set('acc profile') ?>
<section id="update_message" style="display:none;" class="alert success">
	<p><?php echo $this->t('您的信息已更新')?><a class="close" href="#" id="close_thankyou"><?php echo $this->t('关闭')?></a></p>
</section>
<article class="article box">
	<?php echo $this->partial('index/my-account-side.phtml', array('select'=> 'profile')) ?>
	
	<section class="main_section">
		<h3><?php echo $this->t('帐户资料')?><!--帐户资料--></h3>
		<form id="main_form">
		<fieldset>
			<div id="container_uploader" class="photo">
				<figure>
					<img src="<?php echo $this->thumbnail()->scale($this->loggedin_user->profile_picture, 128, 128, true, true);?>" id="holder_pic">
				</figure>
				<div class="file text button company_logo">
					<label><?php echo $this->t('更改商标')?><!--上传个人图像--></label>
					<span class="remark"><?php echo $this->t('每张上限为4MB档案格式：JPEG，JPG，PNG或GIF')?><!--请上传格式为JPEG，JPG，PNG或TIF的图片，每张不超过4M。--></span>
					<button type="button" id="pickfiles"><?php echo $this->t('浏览')?></button><!--浏览-->
				</div>
				<div class="desc"><?php echo $this->t('本人保证拥有使用此图片的一切权利及没有违反<a href="'.$this->geturl('term-of-use','default',null,'default1').'">服务条款</a>。<br>你的资料图片将显示在卖家及宝贝资料页（仅适用于商业帐户）')?></div>
			</div>			
			<div class="text email">
				<label><?php echo $this->t('电邮地址')?></label>
				<input type="text" disabled value="<?php echo $this->loggedin_user->email?>">
				<span class="remark"><?php echo $this->t('若需修改邮箱地址，请<a href="#">联络我们</a>。')?></span>
			</div>
			<div class="text display name col6">
				<label><?php echo $this->t('显示名称')?></label>
				<input type="text" id="username" name="username" value="<?php echo $this->loggedin_user->username?>">
				<span class="remark"><?php echo $this->t('你的名称将显示在卖家及宝贝资料页')?></span>     
				<ul class="errors" id="un_error1" style="display:none;"><li><?php echo $this->t('用户名已被使用')?></li></ul>
				<ul class="errors" id="un_error" style="display:none;"><li><?php echo $this->t('用户名不能留空')?></li></ul>
				<ul class="errors" id="un_error2" style="display:none;"><li><?php echo $this->t('用户名必须是4 - 30个字')?></li></ul>
				<ul class="errors" id="un_success" style="display:none;"><li style="color:#00AA00;"><?php echo $this->t('用户名已被更新')?></li></ul>     
			</div>
			<div class="text tel mobile col6">
				<label><?php echo $this->t('手机号码')?></label>
				<input type="text" id="phone" name="phone" value="<?php echo $this->loggedin_user->phone?>">
				<ul class="errors" id="ph_error1" style="display:none;"><li><?php echo $this->t('电话不能留空')?></li></ul>
				<ul class="errors" id="ph_error2" style="display:none;"><li><?php echo $this->t('只可以填写数字')?></li></ul>
				<ul class="errors" id="ph_success" style="display:none;"><li style="color:#00AA00;"><?php echo $this->t('电话已被更新')?></li></ul>     
			</div>
		<?php if (!empty($this->loggedin_user->cid)):?>
			<div class="text agent number">
				<label><?php echo $this->t('工商执照号码')?></label>
				<input type="text" id="agent_num" name="agent_num" value="<?php echo $this->loggedin_user->license_id?>">                    
				<span class="remark"><?php echo $this->t('刊登物业或汽车广告时，请务必提供工商执照号码')?></span>   
				<ul class="errors" id="ag_success" style="display:none;"><li style="color:#00AA00;"><?php echo $this->t('代理编号被更新')?></li></ul>                      
			</div>
			<div class="text service">
				<label><?php echo $this->t('你公司的主营服务')?></label>
				<input type="text" id="services" name="services" value="<?php echo $this->loggedin_user->services?>">                    
				<span class="remark"><?php echo $this->t('请详细说明你公司的主营内容。如主要是出租豪宅或出售进口车辆等')?></span>
				<ul class="errors" id="se_success" style="display:none;"><li style="color:#00AA00;"><?php echo $this->t('服务已被更新')?></li></ul>      
			</div>
		<?php endif;?>
			
			<h3><?php echo $this->t('联络人资料')?></h3>
			<div class="desc"><?php echo $this->t('在此输入联系人资料，在你发布信息时将自动显示')?>。</div>                                   
			<div class="text contact_name">
				<label><?php echo $this->t('联系人')?></label>
				<input type="text" id="contact_name" name="contact_name" value="<?php echo $this->loggedin_user->contact_name?>">
				<ul class="errors" id="cn_success" style="display:none;"><li style="color:#00AA00;"><?php echo $this->t('联系名已被更新')?></li></ul>     
			</div>
			<div class="text tel col6">
				<label><?php echo $this->t('电话')?></label>
				<input type="text" id="contact_tel" name="contact_tel" value="<?php echo $this->loggedin_user->contact_tel?>">
				<ul class="errors" id="ct_success" style="display:none;"><li style="color:#00AA00;"><?php echo $this->t('联络电话已更新')?></li></ul>     
			</div>
			<div class="msn_qq text col6">
				<label><?php echo $this->t('MSN / QQ')?></label>
				<input type="text" id="contact_msn" name="contact_msn" value="<?php echo $this->loggedin_user->contact_msn?>">
				<ul class="errors" id="cm_success" style="display:none;"><li style="color:#00AA00;"><?php echo $this->t('MSN / QQ已被更新')?></li></ul>     
			</div>
			<div class="button em">
				<button name="profile_btn"><?php echo $this->t('确认提交')?></button>
			</div>
		</fieldset>
	</form>
</article>

<?php /* $this->placeholder('big-section-class')->set('grid_12 main_section') ?>
<?php $this->placeholder('container-class')->set('my_acc profile company setting') ?>
<?php echo $this->partial('index/my-account-side.phtml', array('select'=> 'profile')) ?>
<section class="setting grid_9">
    <h2>
        <span><?php echo $this->t('Profile')?></span>
    </h2>

    <p id="updated_message" class="alert success alert_success hide"><?php echo $this->t('Your Information has been updated')?></p>
    
    <dl id="holder_logo">
        <dt><span><?php echo $this->t('Profile Photo')?><a href="#" id="tips">(Explain)</a></span> <a href="#" rel="profile_photo" class="change" id="change_photo"><?php echo $this->t('Change')?></a><a href="#" rel="profile_photo" class="change" id="hide_photo" style="display:none;"><?php echo $this->t('Hide')?></a></dt>
        <dd class="info"><span><?php echo $this->t('Your Profile Photo')?></span></dd>
        <dd style="display:none;" id="profile_photo">
            <form>      
				<fieldset>       
                    <div id="container_uploader" style="position: relative;margin-left:0px;margin-right: 0px;padding-right: 0px;">
                        <div class="photo desc">
							<img src="<?php echo $this->thumbnail()->scale($this->loggedin_user->profile_picture, 280, 280);?>" id="holder_pic">
						</div>
                        <div class="file text button company_logo">
	                        <label>Company Logo</label>
						    <span>JPG, GIF or PNG format, size limit 2MB</span>
							<input type="text"><button type="button" id="pickfiles"><?php echo $this->t('Browse')?></button>
						</div>
                        <div class="desc">
							<?php echo $this->t('I certify that I have the right to distribute this picture and that it does not violate the <a href="'.$this->geturl('term-of-use','default',null,'default1').'">Terms of Use</a>.')?>
                        </div>
                        <div class="button em">
                            <button><?php echo $this->t('Update')?></button>
                        </div>
                    </div>     
				</fieldset>          
            </form>           
        </dd>
    </dl>
    <dl id="holder_name">
        <dt><span><?php echo $this->t('Name')?><!--a href="#" id="tips3">(Explain)</a--></span><a href="#" rel="profile_name" class="change" id="change_name"><?php echo $this->t('Change')?></a><a href="#" rel="profile_name" class="change" id="hide_name" style="display:none;"><?php echo $this->t('Hide')?></a> </dt>
        <dd class="info" id="infos_names1"><span><?php echo $this->t('Your Real Name')?></span>&nbsp;<em id="profile_name_name">
        <?php
        if ((empty($this->loggedin_user->nm))) {
            echo $this->t('No Information');
        }
        else {
            echo $this->loggedin_user->nm;
        }?></em></dd>
        <dd class="info" id="infos_names2"><span><?php echo $this->t('Your Display Name')?></span>&nbsp;<em id="profile_username_name"><?php echo $this->loggedin_user->username?></em></dd>
        <dd style="display:none;" id="profile_name">
            <form id="profile_name_form">
            	<div class="required"><?php echo $this->t('Required')?></div>
                <fieldset>
                    <!--div class="first_name text col_2">
                        <label class="required"><?php echo $this->t('First Name')?></label>
                        <input type="text" id="profile_firstname" name="firstname" value="<?php echo $this->loggedin_user->firstname?>">
                        <ul class="errors" style="display:none;" id="fn_error"><li><?php echo $this->t('This information is required')?></li></ul>                                
                    </div>     
					<div class="last_name text col_2">
						<label class="required"><?php echo $this->t('Last Name')?></label>
                        <input type="text" id="profile_lastname" name="lastname" value="<?php echo $this->loggedin_user->lastname?>">
                        <ul class="errors" style="display:none;" id="ln_error"><li><?php echo $this->t('This information is required')?></li></ul>
                    </div-->
					<div class="text">
                        <label style="color:#009900"><?php echo $this->t('Real Name')?></label>
                        <input type="text" id="profile_name" name="name" value="<?php echo $this->loggedin_user->nm?>">
                        <ul class="errors" style="display:none;" id="un_error"><li><?php echo $this->t('This information is required')?></li></ul>
                        <!--ul class="errors" style="display:none;" id="un_error1"><li></li></ul>
                        <ul class="errors" style="display:none;" id="un_error2"><li><?php echo $this->t('4 . 30 character limit')?></li></ul-->
                    </div>      
                    <div class="text">
                        <label style="color:#009900"><?php echo $this->t('Display Name')?></label>
                        <input type="text" id="profile_username" name="username" value="<?php echo $this->loggedin_user->username?>">
                        <ul class="errors" style="display:none;" id="un_error"><li><?php echo $this->t('This information is required')?></li></ul>
                        <ul class="errors" style="display:none;" id="un_error1"><li></li></ul>
                        <ul class="errors" style="display:none;" id="un_error2"><li><?php echo $this->t('4 – 30 character limit')?></li></ul>
                    </div>  
                    <div class="button em"><button type="submit"><?php echo $this->t('Update')?></button></div>
                </fieldset>
            </form>
        </dd>
    </dl>
    <dl id="holder_phone">
        <dt><?php echo $this->t('Phone')?> <a href="#" rel="profile_phone" class="change" id="change_phone"><?php echo $this->t('Change')?></a><a href="#" rel="profile_phone" class="change" id="hide_phone" style="display:none;"><?php echo $this->t('Hide')?></a> </dt>
        <dd class="info" id="infos_phone"><span><?php echo $this->t('Your Mobile Number')?></span><em id="profile_phone_name">
            <?php
            if (empty($this->loggedin_user->phone)) {
                echo $this->t('No Information');
            }
            else {
                echo $this->t($this->loggedin_user->phone);
            }?></em></dd>
        <dd style="display:none;" id="profile_phone">
            <form id="profile_phone_form">
                <fieldset>
                    <div class="text">
                        <label for="profile_phone">
                            <?php echo $this->t('Mobile Phone')?>
                        </label>
                        <input type="text" id="profile_phone_number" name="phone" value="<?php echo $this->loggedin_user->phone?>">
                        <ul class="errors" style="display:none;" id="ph_error1"><li><?php echo $this->t('This information is required')?></li></ul>
                        <ul class="errors" style="display:none;" id="ph_error2"><li><?php echo $this->t('Numbers Only')?></li></ul>
                    </div>
                    <div class="button em"><button type="submit"><?php echo $this->t('Update')?></button></div>
                </fieldset>
             </form>
        </dd>
        
    </dl>
</section>
<?php */?>
